﻿using Best.SmartCms.Domain;
using Best.SmartCms.Dto.Response;
using Best.SmartCms.Dto.User;
using Best.SmartCms.Service.Security;
using Microsoft.AspNetCore.Mvc;

namespace Best.SmartCms.API.Controllers
{
    public class UserController : Controller
    {
        private readonly UserService _userService;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="userService"></param>
        public UserController(UserService userService)
        {
            _userService = userService;
        }


        /// <summary>
        /// 用户列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("user/pagelist")]
        public PagedResponse<UserListDto> PageList([FromBody]UserListQueryDto query)
        {
            var ret = _userService.PageList(query);
            return ret;
        }


        /// <summary>
        /// 新增用户
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("user/create")]
        public ApiResponse Create([FromBody]UserEditDto dto)
        {
             _userService.Create(dto);
            return ApiResponse.Succeeds();
        }

        /// <summary>
        /// 修改用户
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("user/edit")]
        public ApiResponse Edit([FromBody]UserEditDto dto)
        {
            _userService.Edit(dto);
            return ApiResponse.Succeeds();
        }


        /// <summary>
        /// 修改用户
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("user/Info")]
        public ApiResponse<UserEditDto> Info(long id)
        {
            var ret = _userService.Info(id);
            return ApiResponse<UserEditDto>.Succeeds(ret);
        }


        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("user/delete")]
        public ApiResponse Delete(long id)
        {
            _userService.Delete(id);
            return ApiResponse.Succeeds();
        }
    }
}